package com.hymall.bean.common;

import com.hymall.bean.MarketTopic;
import com.hymall.bean.vo.AdminTopicReadVo;
import lombok.Data;

/**
 * @author stone
 * @date 2022/01/06 16:24
 */
@Data
public class BaseRespVo<T> {
    T data;
    String errmsg;
    int errno;

    public static <T> BaseRespVo ok(T data) {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setData(data);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

    /**
     * 没有其他返回信息的 BaseRespVo
     *
     * @author: 叶熠彬
     * @date: 2022/7/16 17:35
     * @param: []
     * @return: com.hymall.bean.common.BaseRespVo
     */
    public static <T> BaseRespVo ok() {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

    public static <T> BaseRespVo invalidData(String msg) {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrno(504);
        baseRespVo.setErrmsg(msg);
        return baseRespVo;
    }
    public static <T> BaseRespVo invalidData() {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrno(504);
        baseRespVo.setErrmsg("更新数据已失效");
        return baseRespVo;
    }
    public static <T> BaseRespVo invalidParameter(String msg) {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrno(400);
        baseRespVo.setErrmsg(msg);
        return baseRespVo;
    }
    public static <T> BaseRespVo unAuthc() {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrno(502);
        baseRespVo.setErrmsg("认证失败");
        return baseRespVo;
    }

    /**
     * 返回其他错误状态码的错误信息
     *
     * @author: 叶熠彬
     * @date: 2022/7/16 15:13
     * @param: [error, errmsg]
     * @return: com.hymall.bean.common.BaseRespVo
     */
    public static <T> BaseRespVo error(int error, String errmsg) {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrno(error);
        baseRespVo.setErrmsg(errmsg);
        return baseRespVo;
    }


    public static BaseRespVo ok(Integer[] goods, MarketTopic marketTopic) {
        AdminTopicReadVo adminTopicReadVo = new AdminTopicReadVo();
        adminTopicReadVo.setGoodsList(goods);
        adminTopicReadVo.setTopic(marketTopic);
        return BaseRespVo.ok(adminTopicReadVo);
    }
}
